package com.tobby.demo.jaxb.entity;

import java.util.Set;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Customer {

	String name;

	int age;

	int id;

	public Customer() {
	}

	public Customer(int id, String name, int age) {
		this.id = id;
		this.name = name;
		this.age = age;
	}

	Set<Book> books;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@XmlElementWrapper
	@XmlElement(name = "book")
	public Set<Book> getBooks() {
		return books;
	}

	public void setBooks(Set<Book> books) {
		this.books = books;
	}

	@Override
	public String toString() {
		String result = "Customer [id=" + id + ", name=" + name + ", age="
				+ age + ", books [";
		String separator = "";
		for (Book book : books) {
			result += separator + "Book[id=" + book.getId() + ", name="
					+ book.getName() + ", price=" + book.getPrice() + "]";
			separator = ", ";
		}
		return result + "]]";
	}

}
